package com.kh.samr.controller;

import com.kh.samr.dto.FindListByStartingTimeDto;
import com.kh.samr.dto.ParamPageDto;
import com.kh.samr.entity.expert.ExpertInfo;
import com.kh.samr.service.IExpertInfoService;
import com.kh.samr.utils.ResultDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 专家信息控制器
 *
 * @author Harry
 * @date 2020/12/14
 */
@Api(tags = "专家信息接口")
@RestController
@RequestMapping("/expert_profile")
public class ExpertInfoController {
	
	private static final Logger log = LoggerFactory.getLogger(ExpertInfoController.class);
	
	@Value("${AccessKeySecret}")
	String accessKeySecret;
	
	@Resource
	IExpertInfoService expertInfoService;
	
	/**
	 * 查询所有专家信息
	 *
	 * @param paramPageDto 访问授权凭证字符串及分页参数
	 * @return 查询结果
	 */
	@ApiOperation(value = "查询所有专家信息", notes = "findAll")
	@ApiImplicitParam(name = "paramPageDto",
			value = "访问授权凭证字符串及分页参数", required = true, dataType = "ParamPageDto")
	@PostMapping("/expert_info")
	public ResultDto<List<ExpertInfo>> findAllExpertInfo(
			@RequestBody @Valid ParamPageDto paramPageDto) {
		log.info("方法名称：" + "findAllExpertInfo" +
				";参数：paramPageDto:" + paramPageDto.toString());
		if (StringUtils.equals(this.accessKeySecret, paramPageDto.getAccessKeySecret())) {
			ResultDto<List<ExpertInfo>> result = this.expertInfoService.findAllExpertInfo(paramPageDto);
			log.info("方法名称：" + "findAllExpertInfo" + ";返回值：" + result.toString());
			return result;
		} else {
			ResultDto<List<ExpertInfo>> result = new ResultDto<>(1, "访问授权凭证错误");
			log.error("方法名称：" + "findAllExpertInfo" + ";返回值：" + result);
			return result;
		}
	}
	
	/**
	 * 根据起始时间查询专家列表
	 *
	 * @param findListByStartingTimeDto 根据起始时间查询专家列表Dto
	 * @return 查询结果
	 */
	@ApiOperation(value = "根据起始时间查询专家列表", notes = "findByStartingTime")
	@ApiImplicitParam(name = "findListByStartingTimeDto",
			value = "根据起始时间查询列表Dto", required = true, dataType = "FindListByStartingTimeDto")
	@PostMapping("/expert_info_increment")
	public ResultDto<List<ExpertInfo>> findExpertInfosByCreatTime(
			@RequestBody @Valid FindListByStartingTimeDto findListByStartingTimeDto) {
		log.info("方法名称：" + "findExpertInfosByCreatTime" +
				";参数：accessKeySecretDto:" + findListByStartingTimeDto.toString());
		if (StringUtils.equals(this.accessKeySecret, findListByStartingTimeDto.getAccessKeySecret())) {
			ResultDto<List<ExpertInfo>> result =
					this.expertInfoService.findExpertInfosByCreatTime(findListByStartingTimeDto);
			log.info("方法名称：" + "findExpertInfosByCreatTime" + ";返回值：" + result.toString());
			return result;
		} else {
			ResultDto<List<ExpertInfo>> result = new ResultDto<>(1, "访问授权凭证错误");
			log.error("方法名称：" + "findExpertInfosByCreatTime" + ";返回值：" + result);
			return result;
		}
	}
}
